package com.seecen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seecen.common.BaseResponse;
import com.seecen.common.ResultUtils;
import com.seecen.exception.ErrorCode;
import com.seecen.pojo.entity.RepairType;
import com.seecen.service.RepairTypeService;
import com.seecen.mapper.RepairTypeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class RepairTypeServiceImpl extends ServiceImpl<RepairTypeMapper, RepairType>
        implements RepairTypeService {

    @Override
    public BaseResponse<List<RepairType>> getRepairTypes() {
        try {
            QueryWrapper<RepairType> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("is_enabled", 1)
                    .eq("is_deleted", 0)
                    .orderByAsc("type_id");

            List<RepairType> repairTypes = this.list(queryWrapper);
            return ResultUtils.success(repairTypes);

        } catch (Exception e) {
            log.error("获取维修类型列表失败", e);
            return new BaseResponse<>(ErrorCode.OPERATION_ERROR);
        }
    }
}